package com.zky.enums;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

public enum HealthStatus {
    HEALTHY("健康"),
    SICK("生病"),
    QUARANTINED("隔离"),
    RECOVERING("恢复中"),
    UNKNOWN("未知");

    private final String desc; // 中文描述

    HealthStatus(String desc) {
        this.desc = desc;
    }

    // 告诉 Jackson：序列化/反序列化时使用该字段的值（如"健康"）
    @JsonValue
    public String getDesc() {
        return desc;
    }

    @Override
    public String toString() {
        return desc; // 序列化时调用 toString()，返回中文描述
    }

    @JsonCreator
    public static HealthStatus fromDesc(String desc) {
        for (HealthStatus status : values()) {
            if (status.desc.equals(desc)) {
                return status;
            }
        }
        // 匹配失败时返回默认值或抛异常
        throw new IllegalArgumentException("无效的健康状态: " + desc);
    }
}